home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / amiexpress / source / doors / update / update.c < prev   
Encoding:
C/C++ Source or Header  |  1992-12-26  |  9.0 KB  |  351 lines

  1. #include <exec/types.h>
  2. #include <exec/exec.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include "dh1:source/doors/romconf/doorheader.h"
  6. #define sm sendmessage
  7. #define pm prompt
  8. #define hk hotkey
  9. #define gu getuserstring
  10. #define pu putuserstring
  11.  
  12. #define ACCESS_WRITE -1L
  13. #define ACCESS_READ -2L
  14. char Name[200];
  15. int FindIt(char *str,char *FileName);
  16. void Prepare();
  17. void GiveIt(char *Name,int opt,char *InputName,char *OutPutName);
  18. #define TX(x) (UBYTE)Number.Text[x]
  19. int PurgeIt(char *str,char *FileName,char *NewName);
  20.  
  21. long lock=NULL;
  22. struct REGIT
  23. {
  24.    char Text[8];
  25.    long chksum;
  26. };
  27. struct REGIT Number;
  28. void end();
  29. extern int TLock(char *str);
  30. void sr(char *str);
  31. void end()
  32. {
  33.   if(lock)
  34.     UnLock(lock);
  35.   exit(0);
  36. }
  37. char t[200];
  38. main(int argc,char *argv[])
  39. {
  40.   
  41.   if(argc!=2)
  42.   {
  43.     printf("AutoRegister 1.2, written by Joseph Hodge\n");
  44.     printf("This is an AmiExpress 2.0+(XIM)\n");
  45.     printf("\n\n");
  46.     exit(0);
  47.   }
  48.   Register(argv[1][0]-'0');
  49.     sm("",1);
  50.     sm("AutoRegister 1.2, written by Joseph Hodge",1);
  51.     sm("",1);
  52.   if(!(lock=Lock("REGISTERED:Lockme",ACCESS_WRITE)))
  53.   {
  54.     sm("",1);
  55.     sm("Sorry but an Update is currently being give on another node",1);
  56.     sm("Please try again in a few minutes",1);
  57.     ShutDown();
  58.     end();
  59.   }
  60.    
  61.   gu(Name,DT_NAME);strupr(Name);
  62.   if(!FindIt(Name,"REGISTERED:Revision.Dat"))
  63.   {
  64.     
  65.     sm("",1);
  66.     sm("Your terminal must have ANSI capability to go any further.",1);
  67.     sm("Is your terminal configured for ANSI [Y/n]",0);
  68.     hk(" >:",t);
  69.     if(t[0]=='n' || t[0]=='N')
  70.     {
  71.       sm("No.",1);
  72.       ShutDown();
  73.       end();
  74.     }
  75.     sm("Yes.",1);
  76.     strcpy(t,"VALIDATE");
  77.     pu(t,RETURNCOMMAND);
  78.     Chain("DOORS:FORMEDIT/FORMEDIT",argv[1][0]-'0',WAIT);
  79.     strcpy(t,"");
  80.     pu(t,RETURNCOMMAND);
  81.     if(!FindIt(Name,"REGISTERED:Validate/Validate.db"))
  82.     {
  83.       sm("You must complete the validation FORM.",1);
  84.       sm("Aborting registration.",1);
  85.       ShutDown();
  86.       end();
  87.     }
  88.       
  89.     if(FindIt(Name,"REGISTERED:BetaTester"))
  90.     GiveIt(Name,1,"REGISTERED:AEBeta","REGISTERED:Update.Dat");
  91.     else
  92.     GiveIt(Name,1,"REGISTERED:AE","REGISTERED:Update.Dat");
  93. if(FindIt(Name,"REGISTERED:Developers"))
  94.   {
  95.      sm("Records indicate you are a Developer for AmiExpress",1);
  96.      GiveIt(Name,2,"REGISTERED:Develope.LZH",NULL);
  97.   }
  98.     ShutDown();
  99.     end();
  100.   }
  101. if(FindIt(Name,"REGISTERED:Developers"))
  102.   {
  103.      sm("Records indicate you are a Developer for AmiExpress",1);
  104.      GiveIt(Name,2,"REGISTERED:Develope.LZH",NULL);
  105.   }
  106.  
  107.   
  108.   if(FindIt(Name,"REGISTERED:BetaTester"))
  109.       GiveIt(Name,0,"REGISTERED:AEBETA","REGISTERED:Update.dat");
  110.     else
  111.     {
  112.       if(!FindIt(Name,"REGISTERED:Update.Dat") || FindIt(Name,"REGISTERED:Distributors"))GiveIt(Name,0,"REGISTERED:AE","REGISTERED:Update.Dat");
  113.       else
  114.       {
  115.  
  116.         sm("Sorry but records indicate that you already received",1);
  117.         sm("The latest version of AmiExpress",1);
  118.         ShutDown();
  119.         end();
  120.       }
  121.     }
  122.   ShutDown();
  123.   end();
  124. }
  125.  
  126. int FindIt(char *str,char *FileName)
  127. {
  128.   FILE *fi;
  129.   char image[200];
  130.   if(!TLock(FileName)) return(0);
  131.   strupr(str);
  132.   fi=fopen(FileName,"r");
  133.   while(fgets(image,80,fi)!=NULL)
  134.   {
  135.      sr(image);
  136.      strupr(image);
  137.      if(!strcmp(image,str))
  138.      {
  139.        fclose(fi);
  140.        return(1);
  141.      }
  142.    }
  143.    fclose(fi);
  144.    return(0);
  145. }
  146. int PurgeIt(char *str,char *FileName,char *NewName)
  147. {
  148.   FILE *fi,*fo1,*fo2;
  149.   char image[200];
  150.   int returncode=0;
  151.   if(!TLock(FileName)) return(0);
  152.   sprintf(image,"%s.tmp",FileName);
  153.   if(!TLock(image))
  154.   {
  155.      Rename(FileName,image);
  156.   }
  157.   strupr(str);
  158.   fi=fopen(image,"r");
  159.   fo1=fopen(FileName,"w");
  160.   fo2=fopen(NewName,"a");
  161.   while(fgets(image,80,fi)!=NULL)
  162.   {
  163.      sr(image);
  164.      strupr(image);
  165.      if(!strcmp(image,str))
  166.      {
  167.        fprintf(fo2,"%s\n",image);
  168.        returncode=1;
  169.        
  170.      }
  171.      else fprintf(fo1,"%s\n",image);
  172.    }
  173.    fclose(fi);
  174.    fclose(fo1);
  175.    fclose(fo2);
  176.   sprintf(image,"%s.tmp",FileName);
  177.  
  178.    DeleteFile(image);
  179.    return(returncode);
  180. }
  181.  
  182. void GiveIt(char *Name,int opt,char *InputName,char *OutPutName)
  183.   char Num[200];
  184.   char Temp[10];
  185.   char Test[80];
  186.   long Position;
  187.   char p[200];
  188.   char TypeCode[200];
  189.   char RegNum[200];
  190.   long TruePosition;
  191.   int Got=0;
  192.   int records=0;
  193.   int i;
  194.   int Distributor=0;
  195.   FILE *fi,*st;
  196.   strcpy(t,InputName);
  197.   
  198.   
  199.   if(opt==2)
  200.   {
  201.     sm("",1);
  202.     if(!TLock(InputName))
  203.     {
  204.       sm("Please inform the Sysop that the developer package is",1);
  205.       sm("not available.",1);
  206.       return;
  207.     }
  208.     sm("Preparing Developer Package",1);
  209.     Prepare();
  210.     pu(t,ZMODEMSEND);
  211.     return;
  212.   }
  213.    sm("AmiExpress can be released for specific machine types",1);
  214.    sm("68000, 68030 or 68040.",1);
  215.    if(FindIt(Name,"REGISTERED:Distributors")) Distributor=1;
  216.    if(Distributor)
  217.    {
  218.      sm("Records indicate that you are a distributor.",1);
  219.    }
  220.   if(!Got && !opt){pm("Please Enter registration number >:",RegNum,30);
  221.          sprintf(t,"REG:%s-%s",Name,RegNum); strupr(t);}
  222.          if(!Distributor && !opt)
  223.          {
  224.            if(!PurgeIt(t,"Registered:Update.Dat","REGISTERED:Update.old"))
  225.            {
  226.              sm("",1);
  227.              sm("Records indicate that this is an invalid Registration.",1);
  228.              sm("Please leave a message with the sysop for further assistance.",1);
  229.              sm("",1);
  230.              ShutDown();
  231.              end();
  232.            }
  233.          }
  234.          else
  235.          if(Distributor && !Got && !opt)
  236.          {
  237.              if(!FindIt(t,"Registered:Update.Dat"))
  238.              {
  239.              sm("",1);
  240.              sm("Records indicate that this is an invalid Registration.",1);
  241.              sm("Please leave a message with the sysop for further assistance.",1);
  242.              sm("",1);
  243.              ShutDown();
  244.              end();
  245.              } 
  246.          }
  247.    while(1)
  248.    { 
  249.      while(1)
  250.      {
  251.        
  252.        sm("Please select machine type:",1);
  253.        sm(" 1> 68000",1);
  254.        sm(" 2> 68030",1);
  255.        sm(" 3> 68040",1);
  256.        if(Distributor)sm(" 4> Abort",1);
  257.        hk(" >:",TypeCode);
  258.        TypeCode[1]='\0';
  259.        if(TypeCode[0]=='1'){ sm("68000.",1);sprintf(t,"%s000",InputName); break;}
  260.        if(TypeCode[0]=='2'){ sm("68030.",1);sprintf(t,"%s030",InputName); break;}
  261.        if(TypeCode[0]=='3'){ sm("68040.",1);sprintf(t,"%s040",InputName); break;}
  262.        if(TypeCode[0]=='4' && Distributor) { sm("",1); break; }
  263.        
  264.      }
  265.      if(TypeCode[0]=='4') break;
  266.      if(TypeCode[0]=='1' || TypeCode[0]=='2' || TypeCode[0]=='3')
  267.        {
  268.          if(!records)
  269.          {
  270.            if(opt==1)
  271.            {
  272.             sm("Preparing Revision.",1);
  273.             fi=fopen("REGISTERED:Revision.Dat","a");
  274.             fprintf(fi,"%s\n",Name);
  275.             fclose(fi);
  276.            }
  277.            records=1;
  278.          }
  279.        }
  280.      strcat(t,".LZH");
  281.      sm("",1);
  282.      sm("Preparing main program, please standby.",1);
  283.     if(!TLock(t))
  284.     {
  285.       sm("",1);
  286.       sm("Error! Can't locate Files, please notify sysop!",1);
  287.       sm("",1);
  288.       ShutDown();
  289.       end();
  290.     }
  291.          
  292.         if((!Got && Distributor && opt) || !Distributor)
  293.         {
  294.       
  295.            Number.chksum=time(NULL);
  296.            st=fopen(OutPutName,"a");
  297.            fprintf(st,"=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n");
  298.            fprintf(st,"%s\n",Name);
  299.            fprintf(st,"CheckSum %ld ",Number.chksum);
  300.            fprintf(st,"SumKickDate %s",ctime(&Number.chksum));
  301.            fprintf(st,"REG:%s-%u%u%u%u%u%u%u%u%u-%u.%u%u\n",Name,TX(11),TX(1),TX(9),TX(3),TX(4),TX(8),TX(6),TX(7),TX(5),TX(2),TX(10),TX(0));
  302.            fclose(st); 
  303.            sm("",1);
  304.            sm("Please standby, serializing package..",1); 
  305.            sprintf(p,"%u%u%u%u%u%u%u%u%u-%u.%u%u",TX(11),TX(1),TX(9),TX(3),TX(4),TX(8),TX(6),TX(7),TX(5),TX(2),TX(10),TX(0));
  306.            sm("Your Registration number is >:",0);
  307.            sm(p,0);sm("",1);
  308.    sm("****************************************************************",1);
  309.    sm("Please record your Registration number, It will be needed to get",1);
  310.    sm("product assistance and future updates.",1);
  311.    sm("****************************************************************",1);
  312.    sm("",1);
  313.                
  314.          } 
  315.          if(Distributor) Got=1;   
  316.           Prepare();
  317.           
  318.            pu(t,ZMODEMSEND);
  319.            sm("",1); if(!Distributor) break;
  320.       
  321.      }
  322.      
  323.    sm("",1);
  324.   /* if((records && !Distributor) || (Distributor && opt && Got))
  325.    {
  326.   
  327.    }*/
  328. }
  329.  
  330. void Prepare()
  331. {
  332.   char temp[10];
  333.   sm("",1);
  334.   sm("Please prepare for Zmodem Download.",1);
  335.   sm("press anykey to continue",0);
  336.   hk("",temp);
  337.   sm("",1);
  338. }
  339.  
  340. void sr(char *str)
  341. {
  342.   register int i;
  343.   i=strlen(str)-1;
  344.   while(i>-1)
  345.   {
  346.     if(*(str+i)<=32) *(str+i)='\0'; else break;
  347.     i--;
  348.   }
  349. }
  350.